﻿@{
    Layout = "~/Views/Shared/Index_Layout.cshtml";
}


<table class="layui-hide" id="standardtable" lay-filter="standardtableFilter"></table>


<script type="text/html" id="toolbar">
    <div class="layui-btn-container">

          <a class="common_btn" href="/SysMenu/Create">添加</a>

    </div>
</script>

<script type="text/html" id="tablebar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>

</script>



<script>

    
    var selectedType = null; //父界获取此值，来判断是单选还是多选。参考值：多选，单选
    layui.use(function () {
        var table = layui.treeTable;

        var GSLayui = layui.GSLayui;

        var cols = [

            { title: "序号", width: 60, templet: function (d) { return d.LAY_INDEX; } },
            { field: 'Name', title: '名称' },
            { field: 'Href', title: '链接' },
            { field: 'Sort', title: '排序', width: 100 },
            //{ field: 'status', title: '是否菜单', width: 100 },
            { fixed: "right", title: "操作", width: 190, align: "center", toolbar: "#tablebar" }

        ];
           
        var standardtable = GSLayui.apiTable("standardtable", "/api/SysMenu/DataSysMenu", cols);

        //如果在弹框中加载本页面。注意：parent 是 JS 自带的全局对象，可用于操作父页面
        if (window.name) {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            if (index) {

                //本页面作为子页面，在弹框中的操作按钮
                $("#toolbar").html('<a id="selectValue" class="common_btn" >选择</a>');
                //把父页面的值拿过来
                selectedType = parent.selectedType;

                if (selectedType == '单选') {
                    cols.unshift({ type: 'radio', fixed: 'left' });

                } else {
                    //多选
                    cols.unshift({ type: 'checkbox', fixed: 'left' });
                }

                //删除最后一个操作列
                cols.pop();


            }

        }
 
      
        standardtable.tree = {
            customName: { id: 'Id', name: 'Name'/* , icon: 'Icon' */ },
            view: { expandAllDefault: true }//是否默认展开全部节点

        };
        standardtable.page = false;
        
        table.render(standardtable);

       //选择按钮//子页面上的方法，传给父页面数据
        $('#selectValue').click(function () {
            debugger
            var checkStatus = table.checkStatus('standardtable');
            parent.selectValue(checkStatus.data);

            parent.layer.close(index);

        });
        //表格操作按钮
        table.on('tool(standardtableFilter)', function (obj) {

            switch (obj.event) {

                case 'edit':

                    window.location.href = "/SysMenu/Edit?id=" + obj.data.Id;
                    break;

                case 'delete':
                    layer.confirm('您确认删除？', function (index) {

                        var data = ajaxPost("/api/SysMenu/DeleteMenu/" + obj.data.Id);

                        var isDelete = deletealert(data);
                        if (isDelete)
                            table.reload('standardtable');

                    });
                    break;

            };
        });
     
    });

</script>

